<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript">
    require([ "dojo/_base/array", "dojo/_base/xhr", "dojo/request", "dojo/topic", "dojo/json" ],
            function(array, xhr, request, topic, JSON) {
                var deletItemsCount = 0;
                dutyregisterRestForm = function(formId) {
                    dijit.byId(formId).reset();
                    if (formId.indexOf('UFD') != -1) {
                        var rowid = jQuery("#dutyregisterGird").jqGrid('getGridParam', 'selrow');
                        var dutyregister = jQuery("#dutyregisterGird").jqGrid('getRowData', rowid);
                        dijit.byId('dutyregisterUFD').setValues(dutyregister);
                    }
                };
                topic.subscribe("dutyregister/insertOrUpdate", dutyregisterRestForm);
                var syncDB = function(url, jsonData) {
                    request.post(url, {
                        data : jsonData,
                        headers : {
                            'Content-Type' : "application/json; charset=utf-8"
                        },
                        timeout : 30000
                    }).then(function(response) {
                        topic.publish("notifyMsgTopic", {
                            message : response,
                            type : "message",
                            duration : 1000
                        });
                        var currentPage = jQuery('#dutyregisterGird').jqGrid('getGridParam', 'page');
                        var pageSize = jQuery('#dutyregisterGird').jqGrid('getGridParam', 'rowNum');
                        var totalCount = jQuery('#dutyregisterGird').jqGrid('getGridParam', 'records') - deletItemsCount;
                        var totalPages = Math.ceil(totalCount / pageSize);
                        jQuery("#dutyregisterGird").jqGrid('setGridParam', {
                            page : currentPage > totalPages ? totalPages : currentPage
                        }).trigger("reloadGrid");
                    }, function(error) {
                        alert(error);
                    });
                };
                dutyregisterSubmitForm = function(formId, type) {
                    var url = "dutyregister/insert";
                    if (type == 'u') {
                        url = "dutyregister/update";
                    }
                    var form = dijit.byId(formId);
                    if (form.isValid()) {
                        var json = JSON.stringify(form.getValues(), true);
                        syncDB(url, json);
                        form.hide();
                        topic.publish("dutyregister/insertOrUpdate", formId);
                    } else {
                        form.validate();
                    }
                };
                dutyregisterDelete = function() {
                    var ids = jQuery("#dutyregisterGird").jqGrid('getGridParam', 'selarrrow') || [];
                    deletItemsCount = ids.length;
                    if (ids.length > 0) {
                        if (confirm('确认删除所选定的项？')) {
                            var dutyregister = {};
                            dutyregister.id = '';
                            array.forEach(ids, function(entry, i) {
                                dutyregister.id += entry + ",";
                            });
                            syncDB("dutyregister/delete", JSON.stringify(dutyregister, true));
                        }
                    } else {
                        alert('请选择至少一条数据!');
                    }
                };
                dutyregisterQuery = function(formId) {
                    var dutyregister = dijit.byId(formId).getValues();
                    jQuery("#dutyregisterGird").jqGrid('setGridParam', {
                        postData : dutyregister
                    }).trigger('reloadGrid');
                };
            });
</script>
<div data-dojo-type="dijit/Dialog" id="dutyregisterIFD" title="新增">
  <div class="dijitDialogPaneContentArea">
    <table>
      <tr>
        <td><label for="registerdate">签到时间: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text"
          name="registerdate"></td>
      </tr>
      <tr>
        <td><label for="userid">签到人: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text"
          name="userid"></td>
      </tr>
      <tr>
        <td><label for="fullname">fullname: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text"
          name="fullname"></td>
      </tr>
      <tr>
        <td><label for="regflag">登记标识：1=正常登记（上班，下班）、2＝迟到、3=早退、4＝休息、5＝旷工、6=放假: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text"
          name="regflag"></td>
      </tr>
      <tr>
        <td><label for="regmins">"迟到或早退分钟正常上班时为0": </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text"
          name="regmins"></td>
      </tr>
      <tr>
        <td><label for="reason">迟到原因: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text"
          name="reason"></td>
      </tr>
      <tr>
        <td><label for="dayofweek">周几：1=星期日...7=日期六: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text"
          name="dayofweek"></td>
      </tr>
      <tr>
        <td><label for="inoffflag">上下班标识：1=签到、2=签退: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text"
          name="inoffflag"></td>
      </tr>
      <tr>
        <td><label for="sectionid">班次ID: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text"
          name="sectionid"></td>
      </tr>
    </table>
  </div>
  <div class="dijitDialogPaneActionBar">
    <button data-dojo-type="dijit/form/Button" type="button" onclick="dutyregisterSubmitForm('dutyregisterIFD','i')">保存</button>
    <button data-dojo-type="dijit/form/Button" type="button" onclick="dutyregisterRestForm('dutyregisterIFD');">重置</button>
  </div>
</div>
<div data-dojo-type="dijit/Dialog" id="dutyregisterUFD" title="更新">
  <div class="dijitDialogPaneContentArea">
    <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, readOnly: true" type="text"
      name="registerid" style="display: none;">
    <table>
      <tr>
        <td><label for="registerdate">签到时间: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text"
          name="registerdate"></td>
      </tr>
      <tr>
        <td><label for="userid">签到人: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text"
          name="userid"></td>
      </tr>
      <tr>
        <td><label for="fullname">fullname: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text"
          name="fullname"></td>
      </tr>
      <tr>
        <td><label for="regflag">登记标识：1=正常登记（上班，下班）、2＝迟到、3=早退、4＝休息、5＝旷工、6=放假: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text"
          name="regflag"></td>
      </tr>
      <tr>
        <td><label for="regmins">"迟到或早退分钟正常上班时为0": </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text"
          name="regmins"></td>
      </tr>
      <tr>
        <td><label for="reason">迟到原因: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text"
          name="reason"></td>
      </tr>
      <tr>
        <td><label for="dayofweek">周几：1=星期日...7=日期六: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text"
          name="dayofweek"></td>
      </tr>
      <tr>
        <td><label for="inoffflag">上下班标识：1=签到、2=签退: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text"
          name="inoffflag"></td>
      </tr>
      <tr>
        <td><label for="sectionid">班次ID: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text"
          name="sectionid"></td>
      </tr>
    </table>
  </div>
  <div class="dijitDialogPaneActionBar">
    <button data-dojo-type="dijit/form/Button" type="button" onclick="dutyregisterSubmitForm('dutyregisterUFD','u')">保存</button>
    <button data-dojo-type="dijit/form/Button" type="button" onclick="dutyregisterRestForm('dutyregisterUFD');">重置</button>
  </div>
</div>
<fieldset>
  <legend>&nbsp;&nbsp;信息选项&nbsp;&nbsp;</legend>
  <form id="queryDutyRegisterForm" data-dojo-type="dijit/form/Form" method="post">
    <div style="margin-left: 5px;">
      <table>
        <tr>
          <td><label for="registerdate">签到时间: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="registerdate"></td>
        </tr>
        <tr>
          <td><label for="userid">签到人: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="userid"></td>
        </tr>
        <tr>
          <td><label for="fullname">fullname: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="fullname"></td>
        </tr>
        <tr>
          <td><label for="regflag">登记标识：1=正常登记（上班，下班）、2＝迟到、3=早退、4＝休息、5＝旷工、6=放假: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="regflag"></td>
        </tr>
        <tr>
          <td><label for="regmins">"迟到或早退分钟正常上班时为0": </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="regmins"></td>
        </tr>
        <tr>
          <td><label for="reason">迟到原因: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="reason"></td>
        </tr>
        <tr>
          <td><label for="dayofweek">周几：1=星期日...7=日期六: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="dayofweek"></td>
        </tr>
        <tr>
          <td><label for="inoffflag">上下班标识：1=签到、2=签退: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="inoffflag"></td>
        </tr>
        <tr>
          <td><label for="sectionid">班次ID: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="sectionid"></td>
        </tr>
      </table>
    </div>
  </form>
  <div style="padding: 5px;">
    <button id="dutyregisterInsertBtn" data-dojo-type="dijit/form/Button" type="submit" label="新增">
      <script type="dojo/method" event="onClick" args="evt">
        dijit.byId('dutyregisterIFD').show();
      </script>
    </button>
    <button id="dutyregisterDeleteBtn" data-dojo-type="dijit/form/Button" type="button" label="删除" onclick="dutyregisterDelete();"></button>
    <button id="dutyregisterUpdateBtn" data-dojo-type="dijit/form/Button" type="button" label="更新">
      <script type="dojo/method" event="onClick" args="evt">
        var ids = jQuery("#dutyregisterGird").jqGrid('getGridParam', 'selarrrow') || [];
        if (ids.length != 1) {
          alert('每次只能修改一条数据!');
        }else{
          var dutyregister = jQuery("#dutyregisterGird").jqGrid('getRowData', ids[0]);
          dijit.byId('dutyregisterUFD').setValues(dutyregister);
          dijit.byId('dutyregisterUFD').show();
        }
      </script>
    </button>
    <button id="dutyregisterQueryBtn" data-dojo-type="dijit/form/Button" type="button" label="查询"
      onclick="dutyregisterQuery('queryDutyRegisterForm');"></button>
  </div>
</fieldset>
<div id="gird">
  <table id="dutyregisterGird"></table>
  <div id="dutyregisterToolbar"></div>
</div>
<script type="text/javascript">
    jQuery("#dutyregisterGird").jqGrid({
        url : 'dutyregister/queryAsList',
        datatype : "json",
        autowidth : true,
        rownumbers : true,
        height : 'auto',
        colNames : [
          '签到ID',
          '签到时间',
          '签到人',
          'fullname',
          '登记标识：1=正常登记（上班，下班）、2＝迟到、3=早退、4＝休息、5＝旷工、6=放假',
          '"迟到或早退分钟正常上班时为0"',
          '迟到原因',
          '周几：1=星期日...7=日期六',
          '上下班标识：1=签到、2=签退',
          '班次ID'
        ],
        colModel : [ 
        {
          name : 'registerid',
          index : 'registerid',
          width : 60,
          key : true,
          hidden : true,
          align : 'center'
        },
        {
          name : 'registerdate',
          index : 'registerdate'
        },
        {
          name : 'userid',
          index : 'userid'
        },
        {
          name : 'fullname',
          index : 'fullname'
        },
        {
          name : 'regflag',
          index : 'regflag'
        },
        {
          name : 'regmins',
          index : 'regmins'
        },
        {
          name : 'reason',
          index : 'reason'
        },
        {
          name : 'dayofweek',
          index : 'dayofweek'
        },
        {
          name : 'inoffflag',
          index : 'inoffflag'
        },
        {
          name : 'sectionid',
          index : 'sectionid'
        }
        ],
        rowNum : 15,
        rowList : [ 15, 20, 25, 30 ],
        pager : '#dutyregisterToolbar',
        // sortname : 'username',
        recordpos : 'right',
        viewrecords : true,
        sortorder : "desc",
        jsonReader : {
            repeatitems : false
        },
        multiselect : true,
        shrinkToFit : false,
        caption : "签到表列表"
    });
    jQuery("#dutyregisterGird").jqGrid('navGrid', '#dutyregisterToolbar', {
        edit : false,
        add : false,
        del : false,
        search : false,
        refresh : true
    });
</script>
